#include<bits/stdc++.h>
using namespace std;
int n,q;
int l[300011],r[300011];
void Solve()
{
	
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("study.in","r",stdin);
	freopen("study.out","w",stdout);
	cin >> n >> q;
	for(int i = 1;i < n;i++)
		cin >> l[i] >> r[i];
	if(n <= 1000 && q <= 1000)
	{
		while(q--)
		{
			int op;
			cin >> op;
			if(op == 1)
			{
				int p,s,e;
				cin >> p >> s >> e;
				l[p] = s,r[p] = e;
			}else
			{
				int a,b,c,d;
				long long ans = 0;
				cin >> a >> b >> c >> d;
				while(a != c)
				{
					if(a < c)
					{
						if(b >= r[a])
							ans += b - r[a] + 1,b = r[a] - 1;
						if(b < l[a])
							b = l[a];
						a++,b++;
					}else{
						if(b > r[a - 1])
							ans += b - r[a - 1] + 1,b = r[a - 1] - 1;
						if(b < l[a - 1])
							b = l[a - 1];
						a--,b++;
					}
				}
				if(b > d)
					ans += b - d;
				cout << ans << "\n";
			}
		}
	}else{
		Solve();
	}
	return 0;
}